﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Longbow.Security.Cryptography;
using Bootstrap.Security;
using PetaPoco;
using Longbow.Web.Mvc;

namespace Bootstrap.DataAccess.Model
{
    /// <summary>
    /// CallResultStatic表实体类
    /// </summary>
    [TableName("CallResultStatic")]
    public class CallResultStatistic
    {
        public string ID { get; set; }
        public string CallDate { get; set; } //呼叫时间
        public string InBoundTotal { get; set; }//呼入量
        public string InBoundMax { get; set; }//呼入最大量
        public string InBoundMaxTime { get; set; }//呼入最大量时刻
        public string InBoundMin { get; set; }//呼入最小量
        public string InBoundMinTime { get; set; }//呼入最小量时刻
        public string InboundTalk { get; set; }//呼入接通量
        public string InboundDrop { get; set; }//呼入放弃量
        public string OutBoundTotal { get; set; }//呼出量
        public string OutBoundMax { get; set; }//呼出最大量
        public string OutBoundMaxTime { get; set; }//呼出最大量时刻
        public string OutBoundMin { get; set; }//呼出最小量
        public string OutBoundMinTime { get; set; }//呼出最小量时刻
        public string OutBoundTalk { get; set; }//呼出接通量
        public string OutBoundDrop { get; set; }//呼出放弃量
        public string Intime { get; set; }//进库时间
        public string Date { get; set; } //日期
        public string EndTime { get; set; }//开始日期
        public string BeginTime { get; set; }//结束日期



        //查询呼叫统计sql
        private string _sql = "SELECT *,left(CallDate,10) as Date from  CallResultStatic";
        /// <summary>
        /// 查询呼叫统计
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public virtual Page<CallResultStatistic> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime)
        {
            var sql = new Sql(_sql);
            if (startTime.HasValue) sql.Where("CallDate >= @0", startTime.Value);
            if (endTime.HasValue) sql.Where("CallDate < @0", endTime.Value.AddDays(1).AddSeconds(-1));
            //if (startTime == null && endTime == null) sql.Where("CallDate > @0", DateTime.Today.AddMonths(0 - DictHelper.RetrieveExceptionsLogPeriod()));
            sql.OrderBy($"{po.Sort} {po.Order}");

            return DbManager.Create().Page<CallResultStatistic>(po.PageIndex, po.Limit, sql);
        }


    }
}
